<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GSAP动画标签页</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
            color: #333;
        }

        .tab-container {
            max-width: 800px;
            margin: 20px auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .tabs {
            display: flex;
            flex-wrap: wrap;
            margin-bottom: 20px;
        }

        .tab {
            padding: 10px 20px;
            cursor: pointer;
            background-color: #f8f9fa;
            border: 1px solid #ddd;
            margin-right: 5px;
            border-radius: 5px;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            user-select: none;
        }

        .tab:hover {
            background-color: #e9ecef;
        }

        .tab.active {
            background-color: white;
            border-bottom: 1px solid white;
            margin-bottom: -1px;
            color: #007bff;
            font-weight: bold;
        }

        .tab.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 3px;
            background-color: #007bff;
            animation: underline 0.3s ease-out;
        }

        @keyframes underline {
            from { transform: scaleX(0); }
            to { transform: scaleX(1); }
        }

        .content {
            display: none;
            padding: 20px;
            border: 1px solid #ddd;
            border-top: none;
            background-color: white;
            border-radius: 0 0 5px 5px;
            opacity: 0;
            transform: translateY(10px);
        }

        .content.active {
            display: block;
        }

        .content h3 {
            margin-top: 0;
            color: #2c3e50;
        }

        .content p {
            line-height: 1.6;
        }
    </style>
</head>
<body>
    <div class="tab-container">
        <div class="tab-header">
            <div class="tabs">
                <div class="tab active" data-tab="tab1">Tab 1</div>
                <div class="tab" data-tab="tab2">Tab 2</div>
                <div class="tab" data-tab="tab3">New Tab</div>
                <div class="tab" data-tab="tab4">New Tab</div>
                <div class="tab" data-tab="tab5">New Tab</div>
                <div class="tab" data-tab="tab6">New Tab</div>
            </div>
        </div>
        
        <div class="tab-content">
            <div class="content active" id="tab1">
                <h3>Tab 1 Content</h3>
                <p>This is the content for Tab 1. You can put any HTML content here.</p>
                <p>Try clicking other tabs to see the smooth GSAP animations.</p>
            </div>
            <div class="content" id="tab2">
                <h3>Tab 2 Content</h3>
                <p>This is the content for Tab 2. Each tab has its own content area.</p>
                <p>The transition between tabs is animated with GSAP.</p>
            </div>
            <div class="content" id="tab3">
                <h3>New Tab Content</h3>
                <p>This is a new tab content area.</p>
                <p>You can add as many tabs as you need.</p>
            </div>
            <div class="content" id="tab4">
                <h3>Another New Tab</h3>
                <p>Content for the fourth tab.</p>
                <p>The animation will work smoothly between all tabs.</p>
            </div>
            <div class="content" id="tab5">
                <h3>Fifth Tab</h3>
                <p>This is the fifth tab's content.</p>
                <p>Notice the underline animation on active tab.</p>
            </div>
            <div class="content" id="tab6">
                <h3>Final Tab</h3>
                <p>This is the last tab content.</p>
                <p>New Tab content with full GSAP animation effects.</p>
            </div>
        </div>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const tabs = document.querySelectorAll('.tab');
            let currentTab = document.querySelector('.tab.active');
            let currentContent = document.querySelector('.content.active');
            
            // 初始化第一个内容区域的动画
            gsap.fromTo(currentContent, 
                { opacity: 0, y: 10 },
                { opacity: 1, y: 0, duration: 0.3 }
            );
            
            tabs.forEach(tab => {
                tab.addEventListener('click', function() {
                    if (this === currentTab) return;
                    
                    const tabId = this.getAttribute('data-tab');
                    const newContent = document.getElementById(tabId);
                    
                    // 动画时间线
                    const tl = gsap.timeline();
                    
                    // 1. 淡出当前内容
                    tl.to(currentContent, {
                        opacity: 0,
                        y: -10,
                        duration: 0.2,
                        ease: "power1.out",
                        onComplete: () => {
                            currentContent.classList.remove('active');
                        }
                    });
                    
                    // 2. 切换标签活动状态
                    tl.add(() => {
                        currentTab.classList.remove('active');
                        this.classList.add('active');
                        currentTab = this;
                        
                        newContent.classList.add('active');
                        currentContent = newContent;
                    }, "-=0.1"); // 稍微重叠动画
                    
                    // 3. 淡入新内容
                    tl.fromTo(newContent, 
                        { opacity: 0, y: 10 },
                        { opacity: 1, y: 0, duration: 0.3, ease: "power1.in" }
                    );
                });
            });
        });
    </script>
</body>
</html>
